package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class UserController {

    @Resource
    private UserMapper userMapper;

    @PostMapping("/registerUser")
    private ModelAndView register(User user) {
//        System.out.println(user);
        ModelAndView result = new ModelAndView("register");
        int count = userMapper.countUserByAccount(user.getAccount());
        if(count > 0) {
            result.addObject("msg", "注册失败, 所填写账号已存在");
            return result;
        }
        int rs = userMapper.insertUser(user);
        result.addObject("msg", rs > 0 ? "注册成功" : "注册失败");
        return result;
    }
}
